<html lang="zh-CN">
<head>
	<title>Hibox</title>
</head>
<body style="background-color: #f7f7f7;text-align:center;padding:0;margin: 0;">
<iframe id="ifr" src="" style="width:100%;height:100%;" frameborder="0"></iframe>

<style>
.toast {
  position: fixed;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 5px;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  width: 240px;
  text-align: left;
}

.toast.show {
  opacity: 1;
}

.t1::before {
	content: '...';
	animation: t1ani 3s linear infinite;
}

@keyframes t1ani {
0%, 100% {
	content: '';
}
10% {
	content: '.';
}
20% {
	content: '..';
}
30% {
	content: '...';
}
40% {
	content: '....';
}
50% {
	content: '';
}
60% {
	content: '.';
}
70% {
	content: '..';
}
80% {
	content: '...';
}
90% {
	content: '....';
}
}

/* .t1::before {
	content: '...';
} */
.t2::before {
	content: '3';
	animation: t2ani 4s linear 1s forwards;
}
@keyframes t2ani {
25% {
	content: '2';
}
50% {
	content: '1';
}
75%, 100% {
	content: '0';
}
}
</style>
<!-- <div id="comfirmfloat" style="position: fixed;width: 100%;height: 100%;background: rgba(0,0,0,0.7);left: 0;right: 0;top: 0;bottom: 0;display: none;">
	<div style="width: 300px;height: 200px;background-color: lime;position: absolute;left: 50%;top: 50%;transform: translate(-50%, -50%);border-radius: 10px;display: flex;align-items: center;justify-content: center;">
		<div>
			<div style="font-size: 30px;font-weight: bold;color: #333;">授权成功</div>
			<div style="color: #666;margin-top: 20px;">即将跳转回vscode<span class="t1"></span></div>
			<div style="color: cadetblue;margin-top: 10px;font-size: 30px;font-weight: bold;" class="t2"></div>
		</div>
	</div>
</div> -->

<div class="toast" id="comfirmfloat">
	授权成功，即将跳转回VSCode<span class="t1"></span>
</div>

<script>
function sendJs(e, r) { var o = !1, n = document.createElement("script"); function t() { n && (n.onload = n.onreadystatechange = n.onerror = null, n.parentNode && n.parentNode.removeChild(n), n = null) } r = r || {}, n.charset = r.charset || "utf-8", n.onload = n.onreadystatechange = function () { (/loaded|complete/i.test(this.readyState) || -1 == navigator.userAgent.toLowerCase().indexOf("msie")) && (r.onLoad && r.onLoad(), o || r.ignoreError || (r.onError && r.onError(), window.onerror("", "", "", "", { stack: "servererror:" + (e || "").split("?")[0] })), t()) }, n.onerror = function () { window.__reloadResource && __reloadResource(n), r.onError && r.onError(), t() }, n.src = e, r.defer && (n.defer = "defer"), r.async && (n.async = "async"), r.crossorigin && n.setAttribute("crossorigin", "true"), document.getElementsByTagName("head")[0].appendChild(n) }
window.onerror = function () {}
function $getQuery(name, url) {
	//参数：变量名，url为空则表从当前页面的url中取  
	var u = arguments[1] || window.location.search,
		reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"),
		r = u.substr(u.indexOf("\?") + 1).match(reg);
	return r != null ? r[2] : "";
}  


window.queryback = function (data) {
	console.log(data);
	if (data.ret == 0) {
		// 回跳
		// 提示授权成功
		// const comfirm = document.getElementById('comfirmfloat');
		// comfirm.style.display = '';
		const comfirm = document.querySelector('#comfirmfloat');
		setTimeout(() => {
			comfirm.classList.add('show');
		}, 300)
		// setTimeout(() => {
			
		document.getElementById('ifr').src = 'http://doc.jd.com/szfe/hibox/';

		const isinsiders = $getQuery('isinsiders')
		setTimeout(() => {
			comfirm.style.display = 'none';
			// 如果携带isinsiders则使用vscode-insiders协议
			let tourl = '//hibox-team.hibox/login?info=' + encodeURIComponent(JSON.stringify(data.data));
			if(isinsiders){
				console.log('vscode-insiders:' + tourl);
				location.href = 'vscode-insiders:' + tourl;
			} else {
				console.log('vscode:' + tourl);
				location.href = 'vscode:' + tourl;
			}
		}, 1500)
			
		// }, 3000);

		// 删除掉参数
		history.replaceState({}, '', 'http://wqadmin.jd.com/webstatic/hibox');
	} else {
		// 跳转登录页
		location.href = 'https://ssa.jd.com/sso/login?ReturnUrl=http%3A%2F%2Fwqadmin.jd.com%2Fwebstatic%2Fhibox%3Flogin%3D1';
		// location.href = 'http://wqadmin.jd.com/erplogingw/login?ReturnUrl=http%3A%2F%2Fwqadmin.jd.com%2Fwebstatic%2Fhibox%3Flogin%3D1&clientId=jx-erplogingw';
	}
}
if ($getQuery('login')) {
	sendJs('/webstatic/hibox-login?callback=queryback&_t' + Math.random())
} else {
	document.getElementById('ifr').src = 'http://doc.jd.com/szfe/hibox/';
}
</script>
</body>
</html>